package com.example.administrator.maizuofilm.moviedetails.moviedetailsadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.maizuofilm.R;
import com.example.administrator.maizuofilm.moviedetails.bean.Comment;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by hansen on 2016/7/13.
 */
public class MoviedetailsRecyAdapter extends RecyclerView.Adapter<MoviedetailsRecyAdapter.viewHold> {
private Context context;
   private viewHold hold;
    private List<Comment.DataBean>  list;
    public interface  moviedetailsRecyListen {
        void  onclick(int position,View v);
    };
    private moviedetailsRecyListen recyListen;
    public MoviedetailsRecyAdapter(Context context, List<Comment.DataBean> list, moviedetailsRecyListen recyListen){
        this.context=context;
        this.recyListen=recyListen;
        this.list=list;
    }

    @Override
    public viewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.moviedetails_comment,null);
        hold=new viewHold(view);

        return hold;
    }

    @Override
    public void onBindViewHolder(viewHold holder, int position) {
        holder.userName.setText(list.get(position).getAuthorName());
        holder.commend_com.setText(list.get(position).getReviewContent());
        holder.commend_commendNum.setText(list.get(position).getCommentCounts());
        holder.commend_goodNum.setText(list.get(position).getLikeCount());
        Date date=new Date(Long.valueOf(list.get(position).getReviewTime())*1000);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
       String str= format.format(date);
        holder.commend_time.setText(str);

        Glide.with(context).load(list.get(position).getAuthorHeadPic()).error(R.drawable.iv_comments_icon).into(holder.commend_userPci);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class viewHold extends RecyclerView.ViewHolder {
        TextView userName,commend_com,commend_time,commend_goodNum,commend_commendNum;
        ImageView commend_commPic,commend_goodPic,commend_userPci;
        public viewHold(View itemView) {
            super(itemView);
            userName= (TextView) itemView.findViewById(R.id.userName);
            commend_com= (TextView) itemView.findViewById(R.id.commend_com);
            commend_time= (TextView) itemView.findViewById(R.id.commend_time);
            commend_goodNum= (TextView) itemView.findViewById(R.id.commend_goodNum);
            commend_commendNum= (TextView) itemView.findViewById(R.id.commend_commendNum);
            commend_commPic= (ImageView) itemView.findViewById(R.id.commend_commPic);
            commend_userPci= (ImageView) itemView.findViewById(R.id.commend_userPci);
            commend_goodPic= (ImageView) itemView.findViewById(R.id.commend_goodPic);

            commend_com.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    recyListen.onclick(getLayoutPosition(),v);
                }
            });
        }
    }
}
